
#ifndef __TENET_MGR_H__
#define __TENET_MGR_H__

#ifdef _WIN32
#include <windows.h>
#endif

struct HSock
{
    HSock(void* pData,int iMallocID)
    {
        pkData = pData;
        iMallocID = iMallocID;
    }
    ~HSock()
    {
    }

    const HSock& operator = (const HSock& rkSock)
    {
        pkData = rkSock.pkData;
        iMallocID = rkSock.iMallocID;

        return *this;
    }
    bool operator == (const HSock& rkSock)
    {
        if(pkData == rkSock.pkData && iMallocID == rkSock.iMallocID)
        {
            return true;
        }
        return false;
    }

    void*   pkData;
    int     iMallocID; 
};

class TeNetCall
{
public:
    virtual ~TeNetCall(){}
    virtual void OnAccept(HSock& rkSock,const char* pcIP,int iPort){}
    virtual void OnConnected(HSock& rkSock,const char* pcIP,int iPort){}
    virtual void OnRecv(HSock& rkSock,void *pData,int iSize){}
    virtual void OnDisConnect(HSock& rkSock){}
};

class TeNetMgr
{
public:
    TeNetMgr();
    ~TeNetMgr();

    bool Init(TeNetCall* pkCall,int iThreadCount);
    void Update();
    bool StartListen(const char* pcIP,int iPort,int iSendBufferSize,int iRecvBufferSize);
    bool Connect(const char* pcIP,int iPort,int iSendBufferSize,int iRecvBufferSize);

    bool SendData(HSock& rkSock,void* pData,int iSize);

    void DisConnect(HSock& rkSock);

private:
    void* m_pkData;
};


#endif
